/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.x3.purchasing.order;

import com.x3.purchasing.common.ClassApplicationModule;
import com.x3.purchasing.operator.Operator;
import com.x3.purchasing.operator.OperatorDAO;
import com.x3.purchasing.operator.OperatorDAOImpl;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Session;
import org.zkoss.zk.ui.Sessions;
import org.zkoss.zul.Div;
import org.zkoss.zul.Label;

/**
 *
 * @author kris
 */
public class OrderDetailWnd extends ClassApplicationModule {

    private Session session;
    private OperatorDAO operatorDAO;
    private Label lblNama;
    private Label lblTelp;
    private Label lblEmail;

    public void onCreate() throws Exception {
        operatorDAO = new OperatorDAOImpl();
        lblNama = (Label) getFellow("lblNama");
        lblTelp = (Label) getFellow("lblTelp");
        lblEmail = (Label) getFellow("lblEmail");
        this.loadOperator();
    }

    private void loadOperator() throws Exception {
        session = Sessions.getCurrent();
        Operator operator = operatorDAO.getOperatorByOrder((Integer) session.getAttribute("orderDetailId"));
        lblNama.setValue(operator.getNama());
        lblTelp.setValue(operator.getTelp());
        lblEmail.setValue(operator.getEmail());
        session.removeAttribute("orderDetailId");
    }

    public void cancel() throws Exception {
        redirect("/zul/VendorOrder.zul");
    }

    public void redirect(String url) throws Exception {
        Div contentDiv = (Div) this.getParent();
        contentDiv.getChildren().clear();
        Executions.createComponents(url, contentDiv, null);
    }
}
